package com.yc.cloud.sms.factory;

import com.yc.cloud.sms.sevice.impl.AbstractSmsService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct;

@Component
public class SmsFactory {
    
    private final Map<String, AbstractSmsService> smsServiceMap = new ConcurrentHashMap<>();
    
    @Resource(name = "tencentSmsService")
    private AbstractSmsService tencentSmsService;
    
    @Resource(name = "aliyunSmsService")
    private AbstractSmsService aliyunSmsService;
    
    @PostConstruct
    public void init() {
        smsServiceMap.put(tencentSmsService.getProvider(), tencentSmsService);
        smsServiceMap.put(aliyunSmsService.getProvider(), aliyunSmsService);
    }
    
    /**
     * 获取短信服务实现
     * @param provider 服务商标识（aliyun/tencent）
     * @return 短信服务实现
     */
    public AbstractSmsService getSmsService(String provider) {
        return smsServiceMap.get(provider);
    }
    
    /**
     * 获取默认短信服务实现（默认使用腾讯云）
     * @return 短信服务实现
     */
    public AbstractSmsService getDefaultSmsService() {
        return smsServiceMap.get("tencent");
    }
} 